package com.itheima.controller;

import com.itheima.result.Result;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户管理
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 发送短信验证码
     *
     * @param telephone
     * @return
     */
    @GetMapping("/sendSms")
    public Result sendSMS(@RequestParam String telephone) {
        userService.sendSms(telephone);
        return Result.success();
    }

    /**
     * 登录
     *
     * @param paramMap
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Map<String, String> paramMap) {
        String token = userService.login(paramMap);
        return Result.success(token);
    }

    /**
     * 校验token
     *
     * @param token
     * @return
     */
    @GetMapping("/verify")
    public Result verify(@RequestHeader("Authorization") String token) {
        userService.verify(token);
        return Result.success();
    }
}
